﻿using System;
using System.Collections.Generic;
using System.IO;
using log4net;
using log4net.Config;
namespace AppServer.Core
{
    /// <summary>
    /// 日志
    /// </summary>
    internal class Logger
    {
        /// <summary>
        /// 静态构造函数
        /// </summary>
        static Logger()
        {
            string log4net_xml = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AppServer.log4net");
            XmlConfigurator.ConfigureAndWatch(new FileInfo(log4net_xml));
        }

        static Dictionary<string, ILog> LoggerCache = new Dictionary<string, ILog>();

        /// <summary>
        /// Get Logger
        /// </summary>
        /// <param name="name">Logger Name</param>
        /// <returns>ILog</returns>
        public static ILog GetLogger(string name)
        {
            ILog logger = null;
            lock (LoggerCache)
            {
                if (LoggerCache.ContainsKey(name))
                {
                    logger = LoggerCache[name];
                }
                else
                {
                    logger = LogManager.GetLogger(name);
                    LoggerCache.Add(name, logger);
                }
            }
            return logger;
        }
    }
}
